home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / cgraphix / hatch.c < prev    next >
Text File  |  1986-05-27  |  2KB  |  82 lines

  1. /* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
  2. #include    <stdio.h>
  3. #define    EXTERN    extern
  4. #include    <typedef.h>
  5.  
  6.  
  7. void HatchDirect(x1, y1, x2, y2, Delta)
  8. int        x1, y1, x2, y2, Delta;
  9. {
  10.     int        i,yst,yen,count;
  11.     int        X1RefLoc,X2RefLoc,Y1RefLoc,Y2RefLoc;
  12.     int        DirectModeLoc,ClippingLoc;
  13.     int        X1D,Y1D,X2D,Y2D;
  14.  
  15.     if (Delta == 0)
  16.         return;
  17.  
  18.     HatchGlb = TRUE;
  19.     DirectModeLoc = DirectModeGlb;
  20.     DirectModeGlb = TRUE;
  21.     ClippingLoc = ClippingGlb;
  22.     ClippingGlb = TRUE;
  23.     X1RefLoc = X1RefGlb;
  24.     X1RefGlb = x1;
  25.     X2RefLoc = X2RefGlb;
  26.     X2RefGlb = x2;
  27.     Y1RefLoc = Y1RefGlb;
  28.     Y1RefGlb = y1;
  29.     Y2RefLoc = Y2RefGlb;
  30.     Y2RefGlb = y2;
  31.     yst = y1 + Delta;
  32.     yen = y1 - x2 + x1 + Delta;
  33.     if (Delta < 0) {
  34.         Delta = -Delta;
  35.         i = yst;
  36.         yst = yen;
  37.         yen = i;
  38.     }
  39.     count = (int)((y2-y1+x2-x1+x2-x1) / Delta);
  40.     for (i = 1; i < count; i++ ) {
  41.         X1D = x1;
  42.         Y1D = yst;
  43.         X2D = x2;
  44.         Y2D = yen;
  45.         if (clip(&X1D, &Y1D, &X2D, &Y2D))
  46.             DrawLineDirect(X1D, Y1D, X2D, Y2D);
  47.         yst = yst + Delta;
  48.         yen = yen + Delta;
  49.     }
  50.     ClippingGlb = ClippingLoc;
  51.     HatchGlb = FALSE;
  52.     X1RefGlb = X1RefLoc;
  53.     X2RefGlb = X2RefLoc;
  54.     Y1RefGlb = Y1RefLoc;
  55.     Y2RefGlb = Y2RefLoc;
  56.     DirectModeGlb = DirectModeLoc;
  57. }
  58.  
  59. void Hatch(X_1, Y_1, X_2, Y_2, Delta)
  60. double X_1, Y_1, X_2, Y_2, Delta;
  61. {
  62.     int        x1, y1, x2, y2;
  63.     int        DirectModeLoc;
  64.  
  65.     if (DirectModeGlb)
  66.         HatchDirect((int)(X_1), (int)(Y_1), (int)(X_2), (int)(Y_2),
  67.             (int)(Delta));
  68.     else {
  69.         DirectModeLoc = DirectModeGlb;
  70.         DirectModeGlb = TRUE;
  71.         x1 = WindowX(X_1);
  72.         y1 = WindowY(Y_1);
  73.         x2 = WindowX(X_2);
  74.         y2 = WindowY(Y_2);
  75.         clip(&x1, &y1, &x2, &y1);
  76.         clip(&x1, &y1, &x1, &y2);
  77.         HatchDirect(x1, y1, x2, y2, (int)(Delta));
  78.         DirectModeGlb = DirectModeLoc;
  79.     }
  80. }
  81.  
  82.